$(function() {
	//初始化
	Begin();
})

var thisTabNum = "0";
var A_systemSN = "";//系统序列号
var A_license = "";//系统注册码

var licenseImport = new Vue({
	el: "#licenseImport",
	data: function() {
		//自定义验证，验证机构编码
		var systemSN = function(rule, value, callback) {
			if(!value) {
				return callback(new Error('请输入安装序列号'));
			}
			return callback();
		};
		var license = function(rule, value, callback) {
			if(!value) {
				return callback(new Error('请输入liscense'));
			}
			return callback();
		};
		return {
			licenseForm:{
				systemSNInputCT: 0,
				systemSN:'',
				licenseInputCT: 0,
				license:''
			},
			rules: {
				systemSN: [{
					required: true,
					validator: systemSN,
					trigger: 'blur'
				}],
				license: [{
					required: true,
					validator: license,
					trigger: 'blur'
				}]
			},
			dialogVisible: false,
		}
	},
	methods: {
		descInput: function(inputName) {
			if(inputName == "systemSN") {
				this.licenseForm.systemSNInputCT = this.licenseForm.systemSN.length;
			}
			if(inputName == "license") {
				this.licenseForm.licenseInputCT = this.licenseForm.license.length;
			}
		},
		resetForm: function(formName) {
			//this.$refs['licenseForm'].resetFields();
			licenseImport.licenseForm.license = A_license;
			licenseImport.licenseForm.licenseInputCT = A_license.length;
		},
		submitForm: function(formName) {
			var self = this;
			var params =self.licenseForm;
			this.$refs["licenseForm"].validate(function(valid) {
				if(!valid) {
					return false;
				} else {
					var url = "/system/license/checkLicense";
					VanyAjax(url, params).done(function(data) {
						var isOk = data["isOk"];
						if(isOk=="OK"){
							licenseImport.dialogVisible = true;
						}else{
							this.$message('请输入正确的用户注册码！');
						}
					}, false, self);
				}
			});
		},
		tijiao:function(obj) {
			this.dialogVisible = false;
			var self = this;
			var params =self.licenseForm;
			if(obj) {
				var url = "/system/license/update";
				VanyAjax(url, params).done(function(data) {
					
					A_license = licenseImport.licenseForm.license;
				}, true, self);
			}
		}
	}
	
});

VanyAjax("/system/license/query").done(function(data) {
	licenseImport.licenseForm.systemSN=data["systemSN"];
	A_systemSN = data["systemSN"];
	licenseImport.licenseForm.licenseInputCT=data["license"].length;
	licenseImport.licenseForm.license=data["license"];
	A_license =data["license"];
}, false, this);



//初始化
function Begin() {
	//面包屑
	new Vue().$mount('#crumbs');
	//左菜单滚动
	var oTop = $(".vany_authority").offset().top + 14;
	var sTop = 0;
	$(".vany_authority").scroll(function() {
		sTop = $(this).scrollTop();
		if(sTop >= oTop) {
			$(".conRight>div").css({
				"position": "fixed",
				"top": "60px",
				"right": "38px"
			});
		} else {
			$(".conRight>div").css({
				"position": "absolute",
				"top": "10px",
				"right": "10px"
			});
		}
	});

	sessionStorage.Jurisdiction = ""
}